package com.txunda.zhuohired.aty.manage.home;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.adapter.manage.home.SelectJobTypeAdapter;
import com.txunda.zhuohired.adapter.manage.home.SelectJobTypeLeftAdapter;
import com.txunda.zhuohired.adapter.manage.home.SelectJobTypeRightAdapter;
import com.txunda.zhuohired.base.BaseAty;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/12 14:08
 * 功能描述：职位类型
 * 联系方式：jiahuanchen@126.com
 */

public class SelectJobTypeAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_white_center)
    private TextView tv_layout_white_center;
    /**
     * listView
     */
    @ViewInject(R.id.lv_select_job_type)
    private ListView lv_select_job_type;
    /**
     * 搜索框
     */
    @ViewInject(R.id.et_select_job_type)
    private EditText et_select_job_type;

    @ViewInject(R.id.view_black)
    private View view_black;

    @ViewInject(R.id.ll_select_job_type_next)
    private LinearLayout ll_select_job_type_next;

    @ViewInject(R.id.lv_select_job_type_left)
    private ListView lv_select_job_type_left;

    @ViewInject(R.id.lv_select_job_type_right)
    private ListView lv_select_job_type_right;

    private List<String> jobTypeList;
    private String[] jobTypeStr = {"销售", "智能/高级管理", "运营", "市场", "技术", "教育培训", "金融", "设计", "传媒", "房地产/建筑"};
    private List<String> jobTypeLeftList;
    private String[] jobTypeLeftStr = {"后端开发", "运维/技术支持", "项目管理", "移动开发", "测试", "前端开发", "硬件开发", "数据", "高端技术职位",
            "软件销售技术"};
    private List<String> jobTypeRightList;
    private String[] jobTypeRightStr = {"PHP", "C++", "NET", "C#", "Python", "C", "Hadoop", "Node.js", "Delphi",
            "Golang"};

    private SelectJobTypeAdapter selectJobTypeAdapter;
    private SelectJobTypeLeftAdapter selectJobTypeLeftAdapter;
    private SelectJobTypeRightAdapter selectJobTypeRightAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_white_head);
        tv_layout_white_center.setText("选择职位类型");
    }

    @Override
    @OnClick({R.id.tv_select_job_type_close})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_select_job_type_close://关闭
                view_black.setVisibility(View.GONE);
                ll_select_job_type_next.setVisibility(View.GONE);
                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_select_job_type;
    }

    @Override
    protected void initialized() {
        jobTypeList = new ArrayList<>();
        for (int i = 0; i < jobTypeStr.length; i++) {
            jobTypeList.add(jobTypeStr[i]);
        }
        jobTypeLeftList = new ArrayList<>();
        for (int i = 0; i < jobTypeLeftStr.length; i++) {
            jobTypeLeftList.add(jobTypeLeftStr[i]);
        }
        jobTypeRightList = new ArrayList<>();
        for (int i = 0; i < jobTypeRightStr.length; i++) {
            jobTypeRightList.add(jobTypeRightStr[i]);
        }
    }

    @Override
    protected void requestData() {
        initAdapter();
        et_select_job_type.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                //按下了右下角的搜索,扫描枪测试actionId为0
                //输入法显示的时候，actionId=3，就是右下角的按钮的id
                if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == 0) {
                    // 先隐藏键盘
                    ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(SelectJobTypeAty.this.getCurrentFocus().getWindowToken(),
                                    InputMethodManager.HIDE_NOT_ALWAYS);
                    view_black.setVisibility(View.GONE);
                    ll_select_job_type_next.setVisibility(View.GONE);

                    //                    } else {
                    //                        showErrorTip("请输入搜索内容");
                    //                    }
                }
                return true;
            }
        });
    }

    private void initAdapter() {
        selectJobTypeAdapter = new SelectJobTypeAdapter(this, jobTypeList);
        lv_select_job_type.setAdapter(selectJobTypeAdapter);
        lv_select_job_type.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                initView();
            }
        });

    }

    private void initView() {
        view_black.setVisibility(View.VISIBLE);
        ll_select_job_type_next.setVisibility(View.VISIBLE);
        selectJobTypeLeftAdapter = new SelectJobTypeLeftAdapter(this, jobTypeLeftList);
        lv_select_job_type_left.setAdapter(selectJobTypeLeftAdapter);
        selectJobTypeRightAdapter = new SelectJobTypeRightAdapter(this, jobTypeRightList);
        lv_select_job_type_right.setAdapter(selectJobTypeRightAdapter);
        lv_select_job_type_right.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent();
                intent.putExtra("job_status", jobTypeRightList.get(i).toString());
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}
